<template>
  <div>
    <el-dialog
      :title="$t('payroll_item')"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        
      >
        <el-form-item prop="projectName">
          <el-input
            v-model="queryParams.projectName"
            :placeholder="$t('please_enter', { name: $t('payroll_item_name') })"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="projectCode">
          <el-input
            v-model="queryParams.projectCode"
            :placeholder="$t('please_enter', { name: $t('payroll_item_code') })"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >{{ $t("search") }}</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{
            $t("reset")
          }}</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="tableList" border :max-height="tableHeight">
        <el-table-column
          :label="$t('payroll_item_name')"
          align="center"
          prop="projectName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="$t('payroll_item_code')"
          align="center"
          prop="projectCode"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="$t('project_category')"
          align="center"
          prop="projectType"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.salary_project_type"
              :value="scope.row.projectType"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('settings')">
          <template slot-scope="scope">
            <el-checkbox
              v-model="scope.row.isShowPaySheet"
              true-label="1"
              false-label="0"
              >{{ $t("display_in_payroll_report") }}</el-checkbox
            >

            <el-checkbox
              v-model="scope.row.isShowSalaryReport"
              true-label="1"
              false-label="0"
              >{{ $t("display_in_payslip") }}</el-checkbox
            >
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('action')"
          align="center"
          class-name="small-padding fixed-width"
          width="240"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleCheck(scope.row)"
              >{{ $t("select") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        :page-sizes="[10,20,30,50,100, 200]"
      />
    </el-dialog>
  </div>
</template>

<script>
import { listSalaryProject } from "@/api/salary/salaryProject";
export default {
  props: {},
  dicts: ["salary_project_type"],
  data() {
    return {
      loading: false,
      open: false,
      total: 0,
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
      },
    };
  },
  created() {},

  methods: {
    showModal() {
      this.open = true;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    closeModal() {
      this.open = false;
    },
    getList() {
      this.loading = true;
      listSalaryProject({
        ...this.queryParams,
      }).then((res) => {
        this.tableList = res.rows.map((item) => {
          item.isShowPaySheet = "0";
          item.isShowSalaryReport = "0";
          return item;
        });
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCheck(row) {
      this.$emit("handleCheck", row);
    },
  },
};
</script>
<style scoped lang="scss">
.input-block {
  display: flex;
  align-items: center;
}
</style>
